﻿<Application x:Class="Passwords.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:utils="clr-namespace:Passwords.Utils"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:vm="clr-namespace:Passwords.ViewModels"
             xmlns:locale="clr-namespace:Passwords"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <locale:Locale x:Key="locale"/>
            <sys:Int32 x:Key="itemHeight">28</sys:Int32>
            <utils:BoolToVisibleConverter x:Key="boolToVisible"/>
            <utils:DisplayModeToBoolConverter x:Key="modeToBool"/>
            <utils:DisplayModeToVisibilityConverter x:Key="modeToVis"/>
            <utils:AppDisplayModeToBoolConverter x:Key="appModeToBool"/>
            <utils:AppDisplayModeToVisibilityConverter x:Key="appModeToVis"/>

            <PowerEase EasingMode="EaseOut"  x:Key="fluidEase"/>


            <SolidColorBrush x:Key="AppTextBoxBorderBrush" Color="#FF808080" />
            <SolidColorBrush x:Key="AppAccentBrush" Color="#FF1BA1E2"/>
            <SolidColorBrush x:Key="TransparentChromeBrush" Color="#40808080"/>

            <LinearGradientBrush x:Key="DAppWindowBackground"  StartPoint="0,0" EndPoint="0,200" MappingMode="Absolute"  >
                <LinearGradientBrush.GradientStops>
                    <GradientStop Color="#FF000050" Offset="0"/>
                    <GradientStop Color="Black" Offset="0.4"/>
                </LinearGradientBrush.GradientStops>
            </LinearGradientBrush>
            <SolidColorBrush x:Key="DAppBackground" Color="black"/>
            <SolidColorBrush x:Key="DAppForeground" Color="#ffffffff"/>
            <!--<SolidColorBrush x:Key="DAppWindowBackground" Color="#ff101010"/>-->
            <SolidColorBrush x:Key="DAppChromeBrush" Color="#ff181818"/>
            <SolidColorBrush x:Key="DAppMediumBrush" Color="#ff303030"/>
            <SolidColorBrush x:Key="DAppTextBoxBrush" Color="#FFC0C0C0"/>            
            <DropShadowEffect x:Key="DfocusBitmapEffect" Color="white" ShadowDepth="1"  Opacity="0.8"  BlurRadius="5" />

            <LinearGradientBrush x:Key="LAppWindowBackground"  StartPoint="0,0" EndPoint="0,200" MappingMode="Absolute"  >
                <LinearGradientBrush.GradientStops>
                    <GradientStop Color="#FF88CEEB" Offset="0"/>
                    <GradientStop Color="#FFE1F2F9" Offset="0.2" />
                    <GradientStop Color="White" Offset="0.4"/>
                </LinearGradientBrush.GradientStops>
            </LinearGradientBrush>
            <SolidColorBrush x:Key="LAppForeground" Color="#FF000000"/>
            <SolidColorBrush x:Key="LAppBackground" Color="#FFFFFFFF"/>
            <SolidColorBrush x:Key="LAppChromeBrush" Color="#FFE0E0E0"/>
            <SolidColorBrush x:Key="LAppMediumBrush" Color="#FF808080"/>
            <SolidColorBrush x:Key="LAppTextBoxBrush" Color="#FFF4F4F4"/>
            <DropShadowEffect x:Key="LfocusBitmapEffect" Color="#80000000" Opacity="0.5" ShadowDepth="2" BlurRadius="5"/>


            <SolidColorBrush x:Key="AppWindowBackground" Color="white"/>
            <SolidColorBrush x:Key="AppForeground" Color="#FF000000"/>
            <SolidColorBrush x:Key="AppBackground" Color="#FFFFFFFF"/>
            <SolidColorBrush x:Key="AppChromeBrush" Color="#FFE0E0E0"/>
            <SolidColorBrush x:Key="AppMediumBrush" Color="#FF808080"/>
            <SolidColorBrush x:Key="AppTextBoxBrush" Color="#FFF8F8F8"/>
            <DropShadowEffect x:Key="focusBitmapEffect" Color="#80000000" Opacity="0.5" ShadowDepth="2" BlurRadius="5"/>

            <ControlTemplate TargetType="{x:Type RadioButton}" x:Key="textRadioTemplate">
                <TextBlock x:Name="text" Text="{TemplateBinding Content}"  VerticalAlignment="{TemplateBinding VerticalAlignment}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" Margin="{TemplateBinding Padding}" />
                <ControlTemplate.Triggers>
                    <Trigger Property="IsChecked" Value="True">
                        <Setter Property="Opacity" Value="1"/>
                    </Trigger>
                    <Trigger Property="IsMouseOver" Value="true">
                        <Setter Property="Foreground" Value="#FF1BA1E2"/>
                        <Setter Property="Opacity" Value="1"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>

            <Style TargetType="{x:Type RadioButton}" x:Key="textRadioStyle">
                <!--<Setter Property="Focusable" Value="False"/>-->
                <Setter Property="Template" Value="{StaticResource textRadioTemplate}"/>
                <Setter Property="Foreground" Value="{DynamicResource AppForeground}"/>
                <Setter Property="Margin" Value="3"/>
                <Setter Property="Padding" Value="4"/>
                <Setter Property="Opacity" Value="0.4"/>
                <Setter Property="FontSize" Value="10"/>
                <Setter Property="FontWeight" Value="DemiBold"/>
            </Style>

            <Style TargetType="{x:Type RadioButton}" x:Key="buttonRadioStyle" BasedOn="{StaticResource textRadioStyle}">
                <Setter Property="Opacity" Value="1"/>
            </Style>

            <ControlTemplate TargetType="{x:Type RadioButton}" x:Key="itemRadioTemplate">
                <Border x:Name="Border" Padding="0" SnapsToDevicePixels="true" TextBlock.FontWeight="Normal" Margin="{TemplateBinding Padding}" IsHitTestVisible="True"  BorderBrush="Transparent" BorderThickness="1">
                    <StackPanel Orientation="Horizontal">
                        <Border x:Name="rect" Background="{DynamicResource AppMediumBrush}" Width="24" Height="24" HorizontalAlignment="Left">
                            <ContentPresenter Content="{TemplateBinding Tag}" VerticalAlignment="Center" HorizontalAlignment="Center" />
                        </Border>
                        <ContentPresenter x:Name="presenter"  Margin="5,0,5,0" />
                    </StackPanel>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="true">
                        <Setter Property="Background" Value="#16808080" TargetName="Border"/>
                        <Setter Property="Opacity" Value="0.8"/>
                    </Trigger>
                    <Trigger Property="IsChecked" Value="True">
                        <Setter Property="Foreground" Value="{DynamicResource AppAccentBrush}"/>
                        <Setter Property="Background" TargetName="rect" Value="{DynamicResource AppAccentBrush}"/>
                        <Setter Property="TextBlock.FontWeight" TargetName="presenter" Value="Bold"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>

            <ControlTemplate TargetType="{x:Type Button}" x:Key="radioButtonLikeTemplate">
                <Border>
                    <TextBlock x:Name="text" Text="{TemplateBinding Content}"  TextWrapping="Wrap"
    					Margin="{TemplateBinding Padding}"
    					VerticalAlignment="{TemplateBinding VerticalAlignment}" 
    					HorizontalAlignment="{TemplateBinding HorizontalAlignment}" />
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="true">
                        <Setter Property="Foreground" Value="#FF1BA1E2"/>
                        <!--<Setter  Property="Opacity" Value="1"/>-->
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="false">
                        <Setter TargetName="text" Property="Opacity" Value="0.4"/>
                    </Trigger>

                </ControlTemplate.Triggers>
            </ControlTemplate>


            <Style TargetType="{x:Type RadioButton}" x:Key="itemRadioStyle" BasedOn="{StaticResource textRadioStyle}">
                <Setter Property="Padding" Value="4,3,4,3"/>
                <Setter Property="Template" Value="{StaticResource itemRadioTemplate}"/>
                <Setter Property="VerticalAlignment" Value="Center"/>
                <Setter Property="Margin" Value="9,0,0,0"/>
                <Setter Property="FontSize" Value="14"/>
            </Style>


            <ControlTemplate TargetType="{x:Type Button}" x:Key="buttonTemplate">
                <Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"  >
                    <Grid>
                        <Rectangle Fill="{TemplateBinding Background}" x:Name="fill"/>
                        <ContentPresenter Content="{TemplateBinding Content}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="{TemplateBinding Padding}"/>
                    </Grid>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="true">
                        <Setter Property="Opacity" Value="0.7" TargetName="fill"/>
                    </Trigger>
                    <Trigger Property="IsPressed" Value="true">
                        <Setter Property="Background" Value="Black"/>
                        <Setter Property="Opacity" Value="1" TargetName="fill"/>
                        <!--<Setter Property="BorderBrush" Value="{DynamicResource AppForeground}"/>
                        <Setter Property="BorderThickness" Value="1"/>-->
                        <Setter Property="Effect" TargetName="border" Value="{DynamicResource focusBitmapEffect}"/>
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="false">
                        <Setter Property="Opacity" Value="0.5"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>

            <ControlTemplate TargetType="{x:Type Button}" x:Key="buttonAccentTemplate">
                <Border Background="{TemplateBinding Background}" CornerRadius="0" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                    <Grid>
                        <Rectangle x:Name="rect" Opacity="0" Fill="#30000000"/>
                        <ContentPresenter Content="{TemplateBinding Content}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                    </Grid>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="true">
                        <Setter Property="Opacity" Value="0.8"/>
                    </Trigger>
                    <Trigger Property="IsPressed" Value="true">
                        <Setter Property="Opacity" TargetName="rect" Value="1"/>
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="false">
                        <Setter Property="Opacity" Value="0.5"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>

            <ControlTemplate TargetType="{x:Type Button}" x:Key="textButtonTemplate">
                <Border>
                    <TextBlock Text="{TemplateBinding Content}" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="12" />
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="true">
                        <Setter Property="Foreground" Value="#FF1BA1E2"/>
                        <Setter Property="Opacity" Value="1"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>

            <Style TargetType="{x:Type Button}" x:Key="iconButtonStyle">
                <!--<Setter Property="Background" Value="{DynamicResource AppMediumBrush}"/>-->
                <Setter Property="Background" Value="{DynamicResource AppAccentBrush}"/>
                <Setter Property="BorderBrush" Value="{DynamicResource AppForeground}"/>
                <Setter Property="Foreground" Value="#FFFFFFFF"/>
                <Setter Property="BorderThickness" Value="0.25"/>
                <Setter Property="Width" Value="26"/>
                <Setter Property="Height" Value="26"/>
                <Setter Property="Template" Value="{StaticResource buttonTemplate}"/>
                <Setter Property="Margin" Value="4,0,0,0"/>
            </Style>

            <Style TargetType="{x:Type Button}" x:Key="AccentButtonStyle" BasedOn="{StaticResource iconButtonStyle}">
                <Setter Property="Template" Value="{StaticResource buttonAccentTemplate}"/>
                <Setter Property="Background" Value="{DynamicResource AppAccentBrush}"/>
            </Style>

            <Style TargetType="{x:Type Button}" x:Key="radioLikeButtonStyle">
                <Setter Property="Padding" Value="4"/>
                <Setter Property="FontSize" Value="10"/>
                <Setter Property="Background" Value="{DynamicResource AppMediumBrush}"/>
                <!--<Setter Property="Opacity" Value="0.4"/>-->
                <Setter Property="FontWeight" Value="DemiBold"/>
                <Setter Property="Foreground" Value="{DynamicResource AppForeground}"/>
                <Setter Property="Template" Value="{StaticResource radioButtonLikeTemplate}"/>
            </Style>

            <Style TargetType="{x:Type Button}" x:Key="textButtonStyle" BasedOn="{StaticResource radioLikeButtonStyle}">
                <Setter Property="FontSize" Value="12"/>
                <Setter Property="FontWeight" Value="DemiBold"/>
            </Style>

            <Style TargetType="{x:Type TextBlock}" x:Key="headerText" >
                <Setter Property="VerticalAlignment" Value="Center"/>
                <Setter Property="HorizontalAlignment" Value="Left"/>
                <Setter Property="FontSize" Value="18"/>
                <Setter Property="SnapsToDevicePixels" Value="True"/>
                <Setter Property="FontWeight" Value="Bold"/>
                <Setter Property="Margin" Value="10,0,0,0"/>
            </Style>

            <Style x:Key="focusStyle" TargetType="{x:Type Control}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type Control}">
                            <Border Opacity="0.9" CornerRadius="0">
                                <Rectangle Margin="-6,0" Stroke="Transparent" Width="4" Fill="{DynamicResource AppAccentBrush}" HorizontalAlignment="Left" />
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <Style TargetType="{x:Type ListBox}" x:Key="listBoxStyle">
                <Setter Property="Background" Value="Transparent"/>
                <Setter Property="FocusVisualStyle">
                    <Setter.Value>
                        <Style/>
                    </Setter.Value>
                </Setter>
                <!--<Setter Property="FocusVisualStyle" Value="{StaticResource focusStyle}"/>-->
                <Setter Property="BorderThickness" Value="0"/>
                <Setter Property="Foreground" Value="{DynamicResource AppForeground}"/>
                <Setter Property="Padding" Value="0"/>
                <Setter Property="ItemContainerStyle">
                    <Setter.Value>
                        <Style TargetType="{x:Type ListBoxItem}">
                            <Setter Property="FocusVisualStyle" Value="{StaticResource focusStyle}"/>
                            <Setter Property="Margin" Value="5,0,0,0"/>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                        <Border x:Name="Border" Padding="2,1,2,1" SnapsToDevicePixels="true"  >
                                            <Grid>
                                                <Border x:Name="rect" Background="{DynamicResource AppMediumBrush}" Width="24" Height="24" HorizontalAlignment="Left"/>
                                                <ContentPresenter />
                                            </Grid>
                                        </Border>
                                        <ControlTemplate.Triggers>
                                            <!--<Trigger Property="IsMouseOver" Value="true">
                                                <Setter Property="Opacity" Value="0.8"/>
                                            </Trigger>-->
                                            <Trigger Property="IsSelected" Value="true">
                                                <Setter TargetName="Border" Property="TextBlock.FontWeight" Value="Bold"/>
                                                <Setter TargetName="Border" Property="TextBlock.Foreground" Value="{DynamicResource AppAccentBrush}"/>
                                                <Setter TargetName="rect" Property="Background" Value="{DynamicResource AppAccentBrush}"/>
                                                <Setter TargetName="rect" Property="Effect" Value="{DynamicResource focusBitmapEffect}"/>
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </Setter.Value>
                </Setter>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ListBox}">
                            <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" 
                                    Background="{TemplateBinding Background}" Padding="1" SnapsToDevicePixels="true">
                                <ScrollViewer Focusable="false" Padding="{TemplateBinding Padding}">
                                    <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Margin="0,5,0,0"/>
                                </ScrollViewer>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsGrouping" Value="true">
                                    <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <Trigger Property="IsEnabled" Value="false">
                        <Setter Property="Opacity" Value="0.25"/>
                    </Trigger>
                </Style.Triggers>
            </Style>

            <Style TargetType="{x:Type Separator}" x:Key="emptySepStyle">
                <Setter Property="Width" Value="8"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate/>
                    </Setter.Value>
                </Setter>
            </Style>

            <Style TargetType="{x:Type Separator}" x:Key="lineSepStyle">
                <Setter Property="Width" Value="8"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <Border Background="{DynamicResource AppForeground}" Width="1" HorizontalAlignment="Center" Margin="0,4,0,2" SnapsToDevicePixels="False" Opacity="0.25"/>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <ControlTemplate TargetType="{x:Type Button}" x:Key="addButtonTemplate">
                <Grid x:Name="grid">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Rectangle x:Name="tile" Grid.Column="0" Fill="{DynamicResource AppAccentBrush}" Width="24" Height="24"/>
                    <Image Grid.Column="0" Source="/Passwords;component/Images/appbar.add.rest.png" />
                    <TextBlock x:Name="text" Grid.Column="1" Text="{TemplateBinding Content}" VerticalAlignment="Center" Margin="5,3" Foreground="{DynamicResource AppForeground}" FontWeight="DemiBold"/>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="true">
                        <Setter Property="Opacity" Value="0.7" TargetName="tile"/>
                    </Trigger>
                    <Trigger Property="IsPressed" Value="true">
                        <Setter Property="Background" Value="Black"/>
                        <Setter Property="Opacity" Value="1" TargetName="tile"/>
                        <Setter Property="Effect" TargetName="tile" Value="{DynamicResource focusBitmapEffect}"/>
                        <Setter Property="Foreground" TargetName="text" Value="{DynamicResource AppAccentBrush}"/>
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="false">
                        <Setter Property="Opacity" Value="0.5"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>


            <DataTemplate x:Key="categoryTemplate">
                <Grid x:Name="grid"  SnapsToDevicePixels="False">
                    <TextBlock Text="{Binding Name}" FontSize="14"  VerticalAlignment="Center"                            
    					TextTrimming="CharacterEllipsis" Margin="30,2,4,2"  />
                    <Border Width="24" Height="24" SnapsToDevicePixels="true" HorizontalAlignment="Left">
                        <TextBlock Text="{Binding Passwords.Count}" FontSize="10"  Foreground="White" Margin="0" VerticalAlignment="Center" HorizontalAlignment="Center"  />
                    </Border>
                </Grid>
                <DataTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="true">
                        <Setter Property="Background" Value="#16808080" TargetName="grid"/>
                    </Trigger>
                </DataTemplate.Triggers>
            </DataTemplate>



            <DataTemplate x:Key="passwordTemplate">
                <Grid x:Name="grid" >
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.InputBindings>
                        <MouseBinding Gesture="LeftDoubleClick" Command="{x:Static vm:Commands.EditPasswordCommand}"/>
                    </Grid.InputBindings>
                    <Border Background="Transparent" Width="24" Height="24">
                        <Image Source="/Passwords;component/Images/Lock.png" x:Name="img" />
                    </Border>
                    <TextBlock Grid.Column="1" Text="{Binding Name}" FontSize="14" Margin="5,2,4,2" SnapsToDevicePixels="True"  />
                    <Grid.ContextMenu>
                        <ContextMenu>
                            <MenuItem Header="{Binding rs.MiDelete, Source={StaticResource locale}}" Command="{x:Static vm:Commands.DeletePasswordCommand}"/>
                        </ContextMenu>
                    </Grid.ContextMenu>
                </Grid>
                <DataTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="true">
                        <Setter Property="Background" Value="#16808080" TargetName="grid"/>
                    </Trigger>
                    <DataTrigger  Binding="{Binding IsFavorite}" Value="true">
                        <Setter Property="Source" TargetName="img" Value="/Passwords;component/Images/appbar.favs.rest.png"/>
                    </DataTrigger>
                </DataTemplate.Triggers>
            </DataTemplate>

            <DataTemplate x:Key="fieldTemplate">
                <StackPanel x:Name="stack" Margin="4">
                    <TextBlock Text="{Binding Name}" FontSize="12" Foreground="{DynamicResource AppAccentBrush}" />
                    <TextBlock Text="{Binding Value}" FontSize="14" Foreground="{DynamicResource AppForeground}" TextWrapping="Wrap"  />
                    <StackPanel.ContextMenu>
                        <ContextMenu x:Name="menu" >
                            <MenuItem Header="{Binding rs.MiCopy, Source={StaticResource locale}}" Command="{x:Static vm:Commands.CopyValue}" CommandParameter="{Binding}" />
                        </ContextMenu>
                    </StackPanel.ContextMenu>
                </StackPanel>
                <DataTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="true">
                        <Setter Property="Background" Value="#16808080" TargetName="stack"/>
                    </Trigger>
                    <Trigger Property="IsOpen" SourceName="menu" Value="true">
                        <Setter Property="Background" Value="#16808080" TargetName="stack"/>
                    </Trigger>
                </DataTemplate.Triggers>
               
            </DataTemplate>

            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Styles/ControlsStyles.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>
